<template>
  <div class="ztree" style=" woverflow:auto;cursor: pointer;border-right: cornflowerblue solid ;max-witdh:100%">
    <div class ref="treedemo"></div>
  </div>
</template>

<script>
import { executionSql, executinoSqlWithPage } from "@/config/api";
import "ztree/css/zTreeStyle/zTreeStyle.css";
export default {
  name: "companyTreeData",
  props: {
    tableName: {
      type: String
    }
  },
  // watch: {
  //   tableName(val){
  //     this.tempTable = val;
  //   }
  // },
  data() {
    return {
      // tempTable: this.tableName,
      currentPageNo: 1,
      pageSize: 10,
      totallRows: 0,
      securityTargetList: [],
      companyClassifyDataList: [],
      setting: {
        view: {
          showLine: true,
          showIcon: false,
          txtSelectedEnable: true
        },
        data: {
          simpleData: {
            enable: true,
            idKey: "ID",
            pIdKey: "PID",
            rootPId: ''
          }
        },
        callback: {
          onClick: this.zTreeOnClick //点击选中事件
        }
      },
    };
  },
  created() {
    this.loadComapnyClassify();
  },
  mounted() {
    this.loadComapnyClassify();
  },
  methods: {
    //查询公司分类
    loadComapnyClassify() {
      this.companyClassifyDataList = [];
      executionSql({
        dsCode: "安全树形查询",
        SECURITYTAB: this.tableName,
        PROJECT: localStorage.getItem("project_id"),
        PRO: localStorage.getItem("project_id").substring(0, localStorage.getItem("project_id").length - 3)
      }).then(res => {
        if (res.data.success) {
          this.companyClassifyDataList = res.data.data;
          var tempList = [];
          for (var i = 0; i < this.companyClassifyDataList.length; i++) {
              var zzz = {};
              zzz = res.data.data[i];
              zzz["name"] = res.data.data[i].DESCRIPTION;
              tempList.push(zzz);
          }
          $.fn.zTree.init($(this.$refs.treedemo), this.setting, tempList).expandAll(true);
        }
      })
    },
    //树节点点击事件
    zTreeOnClick(event, treeId, treeNode) {
      this.$emit('confirm', treeNode);
    }
  }
};
</script>